package expressions.slogo;

import parsing.Token;
import expressions.Constant;

/**
 * Represents a true or false value.
 * 
 */
@Token(regex = ":true|:false")
public class BooleanConstant extends Constant<Double>
{
    public static final Double TRUE_VALUE = 1.0D;
    public static final Double FALSE_VALUE = 0.0D;

    public BooleanConstant(String token)
    {
        super(token);
    }

    public static boolean toBoolean(Double d)
    {
        return d >= TRUE_VALUE;
    }

    public static Double toDouble(boolean b)
    {
        return b ? TRUE_VALUE : FALSE_VALUE;
    }

    @Override
    protected Double parseToken(String token)
    {
        return toDouble(token.equals(":true"));
    }

}
